home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / SNAP_CON.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  13.0 KB  |  365 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.output.loaded_image;
  5. import sub_arctic.output.drawable;
  6. import sub_arctic.input.pressable;
  7. import sub_arctic.input.snap_draggable;
  8. import sub_arctic.input.snap_targetable;
  9. import sub_arctic.input.event;
  10. import sub_arctic.input.user_info_holder;
  11. import sub_arctic.lib.manager;
  12.  
  13. import java.awt.Point;
  14.  
  15. /**
  16.  * This is a subclass of drag_container which does snapping behavior.  
  17.  * Snapping is controlled by a set of feature points within a dragged object.
  18.  * This container advertises all the feature points of all its children as its
  19.  * own.  See the snap-drag agent for full details on how snapping works.
  20.  * 
  21.  * @see sub_arctic.input.snap_drag_agent
  22.  * @see sub_arctic.input.snap_draggable
  23.  * @see sub_arctic.input.snap_targetable
  24.  * @author Scott Hudson
  25.  */
  26. public class snap_container extends drag_container implements snap_draggable {
  27.  
  28.   /** 
  29.    * Full constructor.  
  30.    *
  31.    * @param int x initial x position of the container.
  32.    * @param int y initial y position of the container.
  33.    * @param boolean do_bb_feedback do we do bounding box drag feedback.
  34.    */
  35.   public snap_container(int x, int y, boolean do_bb_feedback) 
  36. {
  37.       super(x,y,do_bb_feedback);
  38.     }
  39.  
  40.    //had:
  41.    //* @exception general PROPAGATED.
  42.  
  43.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  44.  
  45.   /** 
  46.    * Handle mouse button press input to the object.  Here, we start dragging.
  47.    *
  48.    * @param event evt the press event.
  49.    * @param Object user_info the information associated with this object at 
  50.    *                         pick time.
  51.    * @return boolean indicating whether we have consumed this event.
  52.    */
  53.   public boolean press(event evt, Object user_info)
  54.     {
  55.       manager.snap_drag_focus.set_focus_to(this, evt, new point_info(0,0));
  56.       return true;
  57.     }
  58.  
  59.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  60.   /* Report our feature points on the basis of our children's points */
  61.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  62.  
  63.   /** 
  64.    * Report number of feature points as sum of visible children's feature
  65.    * points.
  66.    * @return int number of feature points we advertise.
  67.    */
  68.   public int num_feature_points()
  69.     {
  70.       interactor ch;
  71.       int total = 0;
  72.  
  73.       for (int i = 0; i < num_children(); i++)
  74.     {
  75.       ch = child(i);
  76.       if (ch != null && ch.visible()) total += ch.num_feature_points();
  77.     }
  78.  
  79.       return total;
  80.     }
  81.  
  82.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  83.  
  84.   /** 
  85.    * Report a feature point out of our children.  Our feature point indexes
  86.    * are based on placing the first child's indexes after the zeroth, etc. 
  87.    *
  88.    * @param int indx the feature point being asked for.
  89.    * @return Point the feature point requested or 0,0 if index is out of range.
  90.    */
  91.   public Point feature_point(int indx)
  92.     {
  93.       int start_of_ch, start_of_next, i;
  94.       interactor ch;
  95.  
  96.       /* handle index out of range with a default */
  97.       if (indx < 0) return new Point(0,0);
  98.  
  99.       /* find the child that has our index */
  100.       start_of_ch = 0;
  101.       for (i = 0; i < num_children(); i++)
  102.     {
  103.       /* get the child, but process only if its visible */
  104.       ch = child(i);
  105.       if (!ch.visible()) continue;
  106.  
  107.       start_of_next = start_of_ch + ch.num_feature_points();
  108.   
  109.         /* is this the child? */
  110.       if (indx >= start_of_ch && indx < start_of_next)
  111.         {
  112.           /* return the feature point transformed into our coords */ 
  113.           return ch.into_parent(ch.feature_point(indx - start_of_ch));
  114.         }
  115.   
  116.       /* move to the next child */
  117.       start_of_ch = start_of_next;
  118.     }
  119.  
  120.       /* if we get here we have an index out of range and we do the default */
  121.       return new Point(0,0);
  122.     }
  123.  
  124.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  125.  
  126.   /** 
  127.    * Report a feature point enable status out of our children.  Our feature 
  128.    * point indexes are based on placing the first child's indexes after the 
  129.    * zeroth, etc. 
  130.    *
  131.    * @param int indx the index of the feature point we are enquiring about.
  132.    * @return boolean indicating whether that feature point is enabled (we will
  133.    *                 always return false of index out of bounds).
  134.    */
  135.   public boolean feature_point_enabled(int indx)
  136.     {
  137.       int start_of_ch, start_of_next, i;
  138.       interactor ch;
  139.  
  140.       /* handle index out of range with a default */
  141.       if (indx < 0) return false;
  142.  
  143.       /* find the child that has our index */
  144.       start_of_ch = 0;
  145.       for (i = 0; i < num_children(); i++)
  146.     {
  147.       /* get the child, but process only if its visible */
  148.       ch = child(i);
  149.       if (!ch.visible()) continue;
  150.  
  151.       start_of_next = start_of_ch + ch.num_feature_points();
  152.  
  153.         /* is this the child? */
  154.       if (indx >= start_of_ch && indx < start_of_next)
  155.         {
  156.           /* return the feature point at offset index */ 
  157.           return ch.feature_point_enabled(indx - start_of_ch);
  158.         }
  159.   
  160.       /* move to the next child */
  161.       start_of_ch = start_of_next;
  162.     }
  163.  
  164.       /* if we get here we have an index out of range and we do the default */
  165.       return false;
  166.     }
  167.  
  168.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  169.   /* Snap_draggable methods */
  170.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  171.  
  172.   /** 
  173.    * Indicate that the object should snap to a given target object.  Here
  174.    * we move the object to the snap point.
  175.    *
  176.    * @param event           evt             the event "causing" the snap.
  177.    * @param Point           orig_pt         where this object would be without 
  178.    *                                        the snap.
  179.    * @param Point           snap_pt         where this object is with the snap.
  180.    * @param int             feature_pt_indx the feature point of this object 
  181.    *                                        that we are snapping with.
  182.    * @param snap_targetable target_obj      the target object we are snapping 
  183.    *                                        to.
  184.    * @param Object          user_info       the user info for this input.
  185.    * @return boolean indicating if the input has been consumed.
  186.    */
  187.   public boolean snap_to(
  188.     event           evt,
  189.     Point           orig_pt,
  190.     Point           snap_pt,
  191.     int             feature_pt_indx,
  192.     snap_targetable target_obj,
  193.     Object          user_info)
  194.     {
  195.       set_pos(snap_pt); 
  196.       return true;
  197.     }
  198.  
  199.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  200.  
  201.   /** 
  202.    * Perform feedback while a snap is active.  Here we do nothing.
  203.    *
  204.    * @param event           evt             the event "causing" the snap.
  205.    * @param Point           orig_pt         where this object would be without 
  206.    *                                        the snap.
  207.    * @param Point           snap_pt         where this object is with the snap.
  208.    * @param int             feature_pt_indx the feature point of this object 
  209.    *                                        that we are snapping with.
  210.    * @param snap_targetable target_obj      the target object we are snapping 
  211.    *                                        to.
  212.    * @param Object          user_info       the user info for this input.
  213.    * @return boolean indicating if the input has been consumed.
  214.    */
  215.   public boolean snap_feedback(
  216.     event           evt,
  217.     Point           orig_pt,
  218.     Point           snap_pt,
  219.     int             feature_pt_indx,
  220.     snap_targetable target_obj,
  221.     Object          user_info)
  222.     {
  223.       return true;
  224.     }
  225.    
  226.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  227.  
  228.   /** 
  229.    * Indicate that the object is no longer snapped to a given target object.
  230.    * Here we return the object to its nominal position.
  231.    *
  232.    * @param event           evt             the event "causing" the unsnap.
  233.    * @param Point           orig_pt         where this object should be without 
  234.    *                                        the snap.
  235.    * @param Point           snap_pt         where this object was with the snap.
  236.    * @param int             feature_pt_indx the feature point of this object 
  237.    *                                        that we were snapping with.
  238.    * @param snap_targetable target_obj      the target object we were snapping 
  239.    *                                        to.
  240.    * @param Object          user_info       the user info for this input.
  241.    * @return boolean indicating if the input has been consumed.
  242.    */
  243.   public boolean unsnap_to(
  244.     event           evt,
  245.     Point           orig_pt,
  246.     Point           snap_pt,
  247.     int             feature_pt_indx,
  248.     snap_targetable target_obj,
  249.     Object          user_info)
  250.     {
  251.       set_pos(orig_pt); 
  252.  
  253.       return true;
  254.     }
  255.  
  256.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  257.  
  258.   /** 
  259.    * Indicate that the object should anti-snap to a given target object. 
  260.    * Here we just move the object to the anti-snap position.
  261.    *
  262.    * @param event           evt             the event "causing" the anti-snap.
  263.    * @param Point           orig_pt         where this object would be without 
  264.    *                                        the anti-snap.
  265.    * @param Point           snap_pt         where this object is with the 
  266.    *                                        anti-snap.
  267.    * @param int             feature_pt_indx the feature point of this object 
  268.    *                                        that we are anti-snapping with.
  269.    * @param snap_targetable target_obj      the target object we are 
  270.    *                                        anti-snapping to.
  271.    * @param Object          user_info       the user info for this input.
  272.    * @return boolean indicating if the input has been consumed.
  273.    */
  274.   public boolean anti_snap_to(
  275.     event           evt,
  276.     Point           orig_pt,
  277.     Point           snap_pt,
  278.     int             feature_pt_indx,
  279.     snap_targetable target_obj,
  280.     Object          anti_snap_info,
  281.     Object          user_info)
  282.     {
  283.       set_pos(orig_pt); 
  284.       return true;
  285.     }
  286.  
  287.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  288.  
  289.   /** 
  290.    * Perform feedback while an anti-snap is active.  Here we do nothing.
  291.    *
  292.    * @param event           evt             the event "causing" the anti-snap.
  293.    * @param Point           orig_pt         where this object would be without 
  294.    *                                        the anti-snap.
  295.    * @param Point           snap_pt         where this object is with the 
  296.    *                                        anti-snap.
  297.    * @param int             feature_pt_indx the feature point of this object 
  298.    *                                        that we are anti-snapping with.
  299.    * @param snap_targetable target_obj      the target object we are 
  300.    *                                        anti-snapping to.
  301.    * @param Object          user_info       the user info for this input.
  302.    * @return boolean indicating if the input has been consumed.
  303.    */
  304.   public boolean anti_snap_feedback(
  305.     event           evt,
  306.     Point           orig_pt,
  307.     Point           snap_pt,
  308.     int             feature_pt_indx,
  309.     snap_targetable target_obj,
  310.     Object          anti_snap_info,
  311.     Object          user_info)
  312.     {
  313.       return true;
  314.     }
  315.  
  316.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  317.  
  318.   /** 
  319.    * Indicate that the object is no longer anti-snapped to a given target 
  320.    * object.  Here we just move back to our nominal position.
  321.    *
  322.    * @param event           evt             the event "causing" the unanti-snap.
  323.    * @param Point           orig_pt         where this object should be without 
  324.    *                                        the anti-snap.
  325.    * @param Point           snap_pt         where this object was with the 
  326.    *                                        anti-snap.
  327.    * @param int             feature_pt_indx the feature point of this object 
  328.    *                                        that we were anti-snapping with.
  329.    * @param snap_targetable target_obj      the target object we were 
  330.    *                                        anti-snapping to.
  331.    * @param Object          user_info       the user info for this input.
  332.    * @return boolean indicating if the input has been consumed.
  333.    */
  334.   public boolean unanti_snap_to(
  335.     event           evt,
  336.     Point           orig_pt,
  337.     Point           snap_pt,
  338.     int             feature_pt_indx,
  339.     snap_targetable target_obj,
  340.     Object          anti_snap_info,
  341.     Object          user_info)
  342.     {
  343.       set_pos(orig_pt); 
  344.       return true;
  345.     }
  346.  
  347.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  348. }
  349. /*=========================== COPYRIGHT NOTICE ===========================
  350.  
  351. This file is part of the subArctic user interface toolkit.
  352.  
  353. Copyright (c) 1996 Scott Hudson and Ian Smith
  354. All rights reserved.
  355.  
  356. The subArctic system is freely available for most uses under the terms
  357. and conditions described in 
  358.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  359. and appearing in full in the lib/interactor.java source file.
  360.  
  361. The current release and additional information about this software can be 
  362. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  363.  
  364. ========================================================================*/
  365.